<?
	$id = $_POST['id'];
	if($db = new SQLiteDatabase('cs147organizer.db')){
		$command = "SELECT * FROM tasks
			WHERE task_id=%d LIMIT 1";
		$replaced=sprintf($command,$id);
		$result = $db->query($replaced);
		if($result->valid())	{
			$cur = $result->current();
			$cur['due_time_from'] = ($cur['due_time_from'] < 2011996800 ? date('n,j,Y,G,i', $cur['due_time_from']) : '');
			$cur['task_name'] = stripslashes($cur['task_name']);
			$mcom = "SELECT * FROM project_membership WHERE project_id=%d";
			$mcom = sprintf($mcom,$cur['project_id']);
			$r = $db->query($mcom);
			$cur['members'] = '<option value="0">No one</option>';
			while($r->valid())	{
				$c = $r->current();
				$query = "SELECT * FROM users WHERE user_id=%d LIMIT 1";
				$query = sprintf($query,$c['user_id']);
				$r2 = $db->query($query);
				if($r2->valid())	{
					$c2 = $r2->current();
					$cur['members'] .= "<option value=\"" . $c2['user_id'] . "\">" . $c2['username'] . "</option>";
				}
				$r->next();
			}
			$cur['comments'] = '';
			$command = "SELECT * FROM task_comments,users
				WHERE task_comments.deleted=0 AND users.deleted=0
				AND task_comments.user_id=users.user_id AND task_id=%d ORDER BY task_comments.time DESC";
			$replaced=sprintf($command,$cur['task_id']);
			$result = $db->query($replaced);
			while($result->valid()){
				$c = $result->current();
				$cur['comments'] .= "<li class=\"comment\">".stripslashes($c['task_comments.comment'])."<span class=\"author\">"
				.$c['users.username'].
				"</span></li>\n";
				$result->next();
			}
			echo(json_encode($cur));
		}	else	{
			echo(0);
		}
	} else {
		die($err);
	}
?>